package fristphase.day9_15;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class SortListDemo3 {
    public static void main(String[] args) {
        List<Point> list = new ArrayList<>();
        list.add(new Point(0,3));//1000+(x-2)*31+(23+y)
        list.add(new Point(3,43));
        list.add(new Point(12,27));
        list.add(new Point(83,54));
        list.add(new Point(62,46));
        list.add(new Point(19,26));
        System.out.println(list);
        System.out.println(list.get(0).hashCode());//验证Point类型对象的hashCode方法的效果
        System.out.println(1000+(0-2)*31+(23+3));//1000+(x-2)*31+(23+y)

        list.sort(new Comparator<Point>() {
            public int compare(Point o1, Point o2) {
                int len1 = o1.getX()*o1.getX()+o1.getY()*o1.getY();
                int len2 = o2.getX()*o2.getX()+o2.getY()*o2.getY();
                return len1 - len2;//升序，若为true则将(Point o1,Point o2)交换位置
            }
        });

        System.out.println(list);
    }
}
